package com.springcloud.tools.rabbitmq;

import com.rabbitmq.client.Channel;
import com.springcloud.tools.common.TopicConstance;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author fuc
 * @create 2020-06-16
 */
@Component
@Slf4j
public class MQReceiver {

  @RabbitListener(queues = TopicConstance.QUEUE_NAME_TEST)
  public void onMessage(Message message, Channel channel) throws IOException {
    long deliveryTag = message.getMessageProperties().getDeliveryTag();
    // 手工ack
    channel.basicAck(deliveryTag, true);
    log.debug("receive:[{}]", new String(message.getBody()));
  }
}
